<?php
/*
  $Program: ECJC Online Shop
  $Id: application_top.php
  $Based on: osCommerce, Open Source E-Commerce Solutions
  Released under the GNU General Public License
*/

define('_OSCOMMERCE_LOADED', 1);
define('PAGE_PARSE_START_TIME', microtime());
define('PROJECT_VERSION', 'osCommerce 2.2-MS2');
define('MOSCOM_VERSION',  'ECJC v1.2.1RC1');
error_reporting(E_ALL & ~E_NOTICE);

require(DIR_WS_FUNCTIONS . 'compatibility.php');	 

$PHP_SELF = (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']);

define('LOCAL_EXE_GZIP', '/usr/bin/gzip');
define('LOCAL_EXE_GUNZIP', '/usr/bin/gunzip');
define('LOCAL_EXE_ZIP', '/usr/local/bin/zip');
define('LOCAL_EXE_UNZIP', '/usr/local/bin/unzip');

require(DIR_WS_INCLUDES . 'filenames.php');
require(DIR_WS_INCLUDES . 'database_tables.php');
define('BOX_WIDTH', 1); // Depreciated

define('CURRENCY_SERVER_PRIMARY', 'oanda');
define('CURRENCY_SERVER_BACKUP', 'xe');

require(DIR_WS_FUNCTIONS . 'database.php');

tep_db_connect() or die('Unable to connect to database server!');
if($_REQUEST['osMod'] != 'installdb'){
$configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);
  while ($configuration = tep_db_fetch_array($configuration_query)) {
    define($configuration['cfgKey'], $configuration['cfgValue']);
  }

require(DIR_WS_FUNCTIONS . 'general.php');
require(DIR_WS_FUNCTIONS . 'html_output.php');
require(DIR_WS_CLASSES . 'logger.php');
require(DIR_WS_CLASSES . 'shopping_cart.php');
if (!function_exists('session_start')) {
    define('PHP_SESSION_NAME', 'osCAdminID');
    define('PHP_SESSION_PATH', '/');
    define('PHP_SESSION_SAVE_PATH', SESSION_WRITE_DIRECTORY);

    include(DIR_WS_CLASSES . 'sessions.php');
}

require(DIR_WS_FUNCTIONS . 'sessions.php');

tep_session_name('ecjcAdminID');
tep_session_save_path(SESSION_WRITE_DIRECTORY);

// set the session cookie parameters
   if (function_exists('session_set_cookie_params')) {
    session_set_cookie_params(0, DIR_WS_ADMIN);
  } elseif (function_exists('ini_set')) {
    ini_set('session.cookie_lifetime', '0');
    ini_set('session.cookie_path', DIR_WS_ADMIN);
  }

// lets start our session
  tep_session_start();
  //1196
  if ( (PHP_VERSION >= 4.3) && function_exists('ini_get') && (ini_get('register_globals') == false) ) {
    extract($_SESSION, EXTR_OVERWRITE+EXTR_REFS);
  }

// set the language
  if (!tep_session_is_registered('language') || isset($_REQUEST['language'])) {
    if (!tep_session_is_registered('language')) {
      tep_session_register('language');
      tep_session_register('languages_id');
    }
// PLMresearch change define move if brackets for register_gobals=0 to work
  }
// End PLMresearch change define move if brackets for register_gobals=0 to work
    include(DIR_WS_CLASSES . 'language.php');
    $lng = new language();

    if (isset($_REQUEST['language']) && tep_not_null($_REQUEST['language'])) {
      $lng->set_language($_REQUEST['language']);
    } else {
      $lng->get_browser_language();
    }

    $language = $lng->language['directory'];
    $languages_id = $lng->language['id'];


  require(DIR_WS_LANGUAGES . $language . '.php');
  // -- webMS Modification --
  // $current_page = basename($PHP_SELF);
  if($osMod == ''){
  $osMod = isset($_REQUEST['osMod'])?$_REQUEST['osMod']:'index';
  }
  
  if (file_exists(DIR_WS_LANGUAGES . $language . '/' . $osMod . '.php')) {
    include(DIR_WS_LANGUAGES . $language . '/' . $osMod . '.php');
  }
  

require(DIR_WS_FUNCTIONS . 'localization.php');
require(DIR_WS_FUNCTIONS . 'validations.php');

if(! class_exists( 'JConfig' ) || defined('attribs')) {
require(DIR_WS_CLASSES . 'table_block.php');
require(DIR_WS_CLASSES . 'box.php');
require(DIR_WS_CLASSES . 'message_stack.php');
}
  $messageStack = new messageStack;
  
require(DIR_WS_CLASSES . 'split_page_results.php');
require(DIR_WS_CLASSES . 'object_info.php');
require(DIR_WS_CLASSES . 'mime.php');
require(DIR_WS_CLASSES . 'email.php');
require(DIR_WS_CLASSES . 'upload.php');

// calculate category path
  if (isset($_REQUEST['cPath'])) {
    $cPath = $_REQUEST['cPath'];
  } else {
    $cPath = '';
  }

  if (tep_not_null($cPath)) {
    $cPath_array = tep_parse_category_path($cPath);
    $cPath = implode('_', $cPath_array);
    $current_category_id = $cPath_array[(sizeof($cPath_array)-1)];
  } else {
    $current_category_id = 0;
  }

// default open navigation box
  if (!tep_session_is_registered('selected_box')) {
    tep_session_register('selected_box');
    $selected_box = 'configuration';
  }

  if (isset($_REQUEST['selected_box'])) {
    $selected_box = $_REQUEST['selected_box'];
  }

// the following cache blocks are used in the Tools->Cache section
// ('language' in the filename is automatically replaced by available languages)
  $cache_blocks = array(array('title' => TEXT_CACHE_CATEGORIES, 'code' => 'categories', 'file' => 'categories_box-language.cache', 'multiple' => true),
                        array('title' => TEXT_CACHE_MANUFACTURERS, 'code' => 'manufacturers', 'file' => 'manufacturers_box-language.cache', 'multiple' => true),
                        array('title' => TEXT_CACHE_ALSO_PURCHASED, 'code' => 'also_purchased', 'file' => 'also_purchased-language.cache', 'multiple' => true)
                       );
                       //MVS Start
// set the vendor shipping constants
 $vendor_configuration_query = tep_db_query('select configuration_key as 

cfgKey, configuration_value as cfgValue from ' . 

TABLE_VENDOR_CONFIGURATION);
 while ($vendor_configuration = 

tep_db_fetch_array($vendor_configuration_query)) {
   define($vendor_configuration['cfgKey'], 

$vendor_configuration['cfgValue']);
 }
//MVS End

// check if a default currency is set
  if (!defined('DEFAULT_CURRENCY')) {
    $messageStack->add(ERROR_NO_DEFAULT_CURRENCY_DEFINED, 'error');
  }

// check if a default language is set
  if (!defined('DEFAULT_LANGUAGE')) {
    $messageStack->add(ERROR_NO_DEFAULT_LANGUAGE_DEFINED, 'error');
  }

  if (function_exists('ini_get') && ((bool)ini_get('file_uploads') == false) ) {
    $messageStack->add(WARNING_FILE_UPLOADS_DISABLED, 'warning');
  }
// Include OSC-AFFILIATE
  require(DIR_WS_INCLUDES .'affiliate_application_top.php');
  require(DIR_WS_INCLUDES . 'add_ccgvdc_application_top.php');
}
